import Vue from "vue";
import Vuex from "vuex";
import common from "@/store";
import local from "./modules/local";
import session from "./modules/session";
import getters from "./getters";
import createVuexAlong from "vuex-along";
Vue.use(Vuex);
const PAGE = "demo";
const getDefaultState = () => {
  return {
    ...common.state
  };
};
const store = new Vuex.Store({
  strict: process.env.NODE_ENV !== "production",
  state: getDefaultState(),
  modules: {
    [PAGE]: {
      state: { ...local.state, ...session.state },
      mutations: { ...local.mutations, ...session.mutations },
      actions: { ...local.actions, ...session.actions }
    }
  },
  getters,
  mutations: {
    ...common.mutations
  },
  actions: {
    ...common.actions
  },
  plugins: [
    createVuexAlong({
      local: {
        list: [
          ...common.local,
          ...Object.keys(local.state).map(key => `${PAGE}.${key}`)
        ]
      },
      session: {
        list: [
          ...common.session,
          ...Object.keys(session.state).map(key => `${PAGE}.${key}`)
        ]
      }
    })
  ]
});

export default store;
